Fix/anthropic api compatibility#2603
Merged
danielaskdd merged 2 commits intoHKUDS:mainfrom Jan 19, 2026
Merged
Conversation
…cking in stream response
Added hasattr check for 'text' attribute before accessing event.delta.text
Not all Delta events have a 'text' attribute (e.g., message_delta vs content_block_delta)
Fixes streaming response AttributeError and 400 BadRequest errors when using Anthropic Claude models.
… parameter instead of adding to messages array Anthropic API only accepts 'user' and 'assistant' roles in messages array. System prompts must be passed as a top-level parameter to messages.create()
Collaborator
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes Anthropic Claude API compatibility issues in the anthropic.py LLM adapter.
This PR addresses two bugs that prevent proper usage of Anthropic Claude models:
Changes Made
System prompt parameter fix (lines 103-126):
systemparameter tomessages.create()Error code: 400 - messages: Unexpected role "system"Delta attribute checking fix (line 138):
hasattr(event.delta, "text")check before accessingevent.delta.texttextattribute on their delta objectAttributeError: 'Delta' object has no attribute 'text'Checklist
Additional Notes
Testing performed:
claude-sonnet-4-5-20250929modelAPI Documentation Reference:
Breaking Changes: None - this is a bug fix that makes the adapter work as intended.
Compatibility: Compatible with all current Anthropic Claude models (Claude 3, Claude 3.5, Claude Opus 4.5, etc.)